package com.jbp.controller;

import com.jbp.model.Gift;
import com.jbp.model.GiftShop;
import com.jbp.service.GiftService;
import com.jbp.utils.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.stream.Collectors;


/**
 * 礼物
 */
@Api(hidden = true)
@ApiIgnore
@RestController
@RequestMapping("/rest/gift")
public class GiftController {
    @Autowired
    private GiftService giftService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(){
        List<Gift> gifts = giftService.distinctGiftList();

        /*List<GiftShop> list = giftService.list().stream().map(gift -> {
            GiftShop giftShop = new GiftShop();
            giftShop.setGiftId(gift.getId());
            giftShop.setGiftName(gift.getName());
            giftShop.setGiftCoin(gift.getCoin());
            giftShop.setGiftImgUrl(gift.getImgUrl());
            giftShop.setGiftCartoonUrl(gift.getCartoonUrl());
            return giftShop;
        }).collect(Collectors.toList());*/

        List<GiftShop> list = gifts.stream().map(gift -> {
            GiftShop giftShop = new GiftShop();
            giftShop.setGiftId(gift.getId());
            giftShop.setGiftName(gift.getName());
            giftShop.setGiftCoin(gift.getCoin());
            giftShop.setGiftImgUrl(gift.getImgUrl());
            giftShop.setGiftCartoonUrl(gift.getCartoonUrl());
            return giftShop;
        }).collect(Collectors.toList());

        return R.ok(list);
    }
}
